#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstring>

class String {
private:
    char* data;

public:
    String(const char* str = "") {
        data = new char[strlen(str) + 1];
        strcpy(data, str);
    }

    String(const String& other) {
        data = new char[strlen(other.data) + 1];
        strcpy(data, other.data);
    }

    ~String() {
        delete[] data;
    }

    String& operator=(const char* str) {
        delete[] data;
        data = new char[strlen(str) + 1];
        strcpy(data, str);
        return *this;
    }

    String& operator=(const String& other) {
        delete[] data;
        data = new char[strlen(other.data) + 1];
        strcpy(data, other.data);
        return *this;
    }

    String operator+(const String& other) {
        String result;
        result.data = new char[strlen(data) + strlen(other.data) + 1];
        strcpy(result.data, data);
        strcat(result.data, other.data);
        return result;
    }

    String& operator+=(const String& other) {
        char* newData = new char[strlen(data) + strlen(other.data) + 1];
        strcpy(newData, data);
        strcat(newData, other.data);
        delete[] data;
        data = newData;
        return *this;
    }

    char& operator[](int index) {
        return data[index];
    }

    bool operator==(const String& other) {
        return strcmp(data, other.data) == 0;
    }

    bool operator<(const String& other) {
        return strcmp(data, other.data) < 0;
    }

    friend std::istream& operator>>(std::istream& in, String& str);
    friend std::ostream& operator<<(std::ostream& out, String& str);

    int Length() const {
        return strlen(data);
    }
};

std::istream& operator>>(std::istream& in, String& str) {
    char buf[1000];
    in >> buf;
    str = buf;
    return in;
}

std::ostream& operator<<(std::ostream& out, String& str) {
    out << str.data;
    return out;
}

int main() {
    String s1("Help!"), s2("Good!"), s3(s2), s4, s5;

    std::cout << "s1=" << s1 << std::endl;

    s3 = "Hello!";
    std::cout << "s3=" << s3 << std::endl;

    s3 = s2;
    std::cout << "s3=" << s3 << std::endl;

    s3 += s2;
    std::cout << "s3=" << s3 << std::endl;

    std::cin >> s4;
    std::cout << "s4=" << s4 << std::endl;

    s5 = s3 + s4;
    std::cout << "s5=" << s5 << std::endl;

    s5[0] = 'g';
    std::cout << "s5=" << s5 << std::endl;

    std::cout << "strlen(s5)=" << s5.Length() << std::endl;

    std::cout << std::boolalpha << (s3 == s1) << std::endl;

    return 0;
}